﻿/// <reference path="../jquery-1.5.1.min.js" />
/// <reference path="../jquery-ui-1.8.11.min.js" />


    var linkObj;

    $(document).ready(function () {

        $('#DialogDiv').dialog({
            autoOpen: false,
            width: "auto",
            show: { effect: 'slide', direction: "up", duration: 500 },
            hide: { effect: 'slide', direction: "up", duration: 500 },
            resizable: false,
            modal: true,
            buttons: {
                Submit: function () {
                    $("#poErrorMessage").html(''); //make sure there is nothing on the message before we continue                         
                    $("#DialogeForm").submit();
                },
                "Cancel": function () {
                    $(this).dialog("close");

                    //refreshGrid();
                }
            }
        });

        $("a:.create, a:.edit, a:.copy, a:.delete").live("click", function () {

            //change the title of the dialog
            linkObj = $(this);

            var dialogDiv = $('#DialogDiv');
            var viewUrl = linkObj.attr('href');
            $.get(viewUrl, function (data) {
                dialogDiv.html(data);
                //validation
                var $form = $("#DialogeForm");
                // Unbind existing validation
                $form.unbind();
                $form.data("validator", null);
                // Check document for changes
                $.validator.unobtrusive.parse(document);
                // Re add validation with changes
                $form.validate($form.data("unobtrusiveValidation").options);
                //open dialog
                dialogDiv.dialog('open');
            });
            return false;
        });

    });


    function poUpdateSuccess(data) {
        if (data.Success == true) {           
            //notification
            $('#successmessage').html("Successfull!");
            $('#successmessage').delay(100).slideDown(400).delay(3000).slideUp(400);
            
        }
        else {
            $("#poErrorMessage").html(data.ErrorMessage);
            $("#poErrorMessage").show();
        }
    }

    function refreshGrid() {
        var grid = $("#TestGrid").data("tGrid");
        //send additional arguments by passing them as a literal JavaScript object
        grid.rebind();
    }
